//
//  LMainVC.m
//  LXing
//
//  Created by L on 2017/5/10.
//  Copyright © 2017年 L. All rights reserved.
//

#import "LMainVC.h"

@interface LMainVC ()

@property (nonatomic, assign) NSInteger index;

@end

@implementation LMainVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    _index = 1;
    
    NSArray *array = @[ @{@"vc":@"LExerciseCircleVC",@"image":@"ic_tab_circle",@"title":@"运动圈"},
                        @{@"vc":@"LDiscoverVC",@"image":@"ic_tab_discovered",@"title":@"发现"},
                        @{@"vc":@"LExerciseVC",@"image":@"ic_tab_sports",@"title":@"运动"},
                        @{@"vc":@"LShoppingVC",@"image":@"ic_tab_message",@"title":@"信息"},
                        @{@"vc":@"LMineVC",@"image":@"ic_tab_mine",@"title":@"我的"}];
    
    NSMutableArray *arrVC = [[NSMutableArray alloc] init];
    for (NSDictionary *dict in array)
    {
        UIViewController *vc = [self getVC:dict[@"vc"] Image:dict[@"image"] Title:dict[@"title"]];
        [arrVC addObject:vc];
    }
    
    self.tabBar.tintColor = [UIColor colorWithRed:52/255.0 green:185/255.0 blue:105/255.0 alpha:1];
    self.viewControllers = arrVC;
    self.tabBar.translucent = NO;
}

- (UIViewController *)getVC:(NSString *)clsName Image:(NSString *)image Title:(NSString *)title
{
    Class cls = NSClassFromString(clsName);
    UIViewController *vc = [[cls alloc] init];
    
    vc.tabBarItem.title = title;
    
    NSString *imageNormal = [NSString stringWithFormat:@"%@_normal_22x22_",image];
    NSString *imageSelected = [NSString stringWithFormat:@"%@_selected_22x22_",image];
    vc.tabBarItem.image = [UIImage imageNamed:imageNormal];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:imageSelected] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    
    if (_index != 3)
    {
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
        vc.navigationItem.title = title;
        
        UITableView *tabView = [[UITableView alloc] initWithFrame:self.view.bounds];
        [vc.view addSubview:tabView];
        
        _index += 1;
        return nav;
    }
    
    _index += 1;
    return vc;
}

@end
